package com.lzy.system.organization.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzy.exception.BusException;
import com.lzy.system.organization.dto.SysRoleNavAddDTO;
import com.lzy.system.organization.dto.convert.SysRoleNavConvert;
import com.lzy.system.organization.entity.SysRoleNav;
import com.lzy.system.organization.mapper.SysRoleNavMapper;
import com.lzy.system.organization.service.ISysRoleNavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 角色对应导航 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2023-12-06
 */
@Service
public class SysRoleNavServiceImpl extends ServiceImpl<SysRoleNavMapper, SysRoleNav> implements ISysRoleNavService {

    SysRoleNavConvert sysNavConvert;

    @Autowired
    public SysRoleNavServiceImpl(SysRoleNavConvert sysNavConvert) {
        this.sysNavConvert = sysNavConvert;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(Integer roleid,List<SysRoleNavAddDTO> list) throws BusException {
        List<SysRoleNav> sysRoleNavs = sysNavConvert.addDTOToListEntity(list);
        this.remove(new QueryWrapper(){{
            eq("role_id",roleid);
        }});
        this.saveBatch(sysRoleNavs);
    }
}
